package com.ruoyi.warning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.warning.domain.entity.Template;
import com.ruoyi.warning.domain.query.TemplateQuery;
import com.ruoyi.warning.mapper.TemplateMapper;
import com.ruoyi.warning.service.ITemplateService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 告警模版表 服务实现类
 * </p>
 *
 * @author chenhc
 * @since 2025-02-06
 */
@Service
public class TemplateServiceImpl extends ServiceImpl<TemplateMapper, Template> implements ITemplateService {

    @Override
    public TableDataInfo getTemplatePage(TemplateQuery query) {
        Page<Object> page = PageHelper.startPage(query.getPageNum(),query.getPageSize());
        LambdaQueryWrapper<Template> wrapper = new QueryWrapper<Template>().lambda();
        List<Template> list = this.list(wrapper
                .like(ObjectUtils.isEmpty(query.getTemplateName()),Template::getTemplateName,query.getTemplateName())
                .eq(ObjectUtils.isEmpty(query.getWarningWay()),Template::getWarningWay,query.getWarningWay()));
        TableDataInfo tableDataInfo = new TableDataInfo(list, page.getTotal());
        return tableDataInfo;
    }

    @Override
    public List<Template> getTemplateList(TemplateQuery query) {
        LambdaQueryWrapper<Template> wrapper = new QueryWrapper<Template>().lambda()
                .like(ObjectUtils.isEmpty(query.getTemplateName()), Template::getTemplateName, query.getTemplateName())
                .eq(ObjectUtils.isEmpty(query.getWarningWay()), Template::getWarningWay, query.getWarningWay());
        return this.list(wrapper);
    }

    @Override
    public String saveTemplate(Template template) {
        this.save(template);
        return null;
    }

    @Override
    public String deleteTemplate(List<String> ids) {
        this.removeByIds(ids);
        return null;
    }

    @Override
    public String updateTemplate(Template template) {
        this.updateById(template);
        return null;
    }

    @Override
    public Template getDetails(Long id) {
        return this.getById(id);
    }


}
